package cc.ufinity.networkdiagnose.view;

import cc.ufinity.networkdiagnose.widget.TestWidget;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

public class TestActivity extends AbstractActivity {

	private TestWidget tw;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tw = new TestWidget(this);
		this.setContentView(tw);
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

/*	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (KeyEvent.KEYCODE_BACK == keyCode) {
			Log.d("返回 网络测试", "返回按钮");
			TestWidget tw = new TestWidget(this);
			this.setContentView(tw);
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
		
		if(keyCode==KeyEvent.KEYCODE_BACK){
			setContentView(tw);	
			return true;
			}else if(keyCode==KeyEvent.KEYCODE_MENU){
				AlertDialog.Builder builder = new AlertDialog.Builder(this);
				builder.setTitle("提示");
				builder.setIcon(R.drawable.what);
				builder.setMessage("确定退出系统吗？");
				builder.setCancelable(false);
				builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						android.os.Process.killProcess(android.os.Process.myPid());
					}
				});
				builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					}
				});
				builder.show();
			}
		return false;
	}
	
}
